<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="group9.UserStory" %>
<%@ page import="group9.User" %>
<%@ page import="java.util.LinkedList" %>
<html>

<!-- Claudio Herreros, Dylan James, Tyler Berg -->

<%
	User user = (User)session.getAttribute("User");
	
	if (user == null){
	response.sendRedirect("login.jsp");
	}
	UserStory user_story;
	try{
	if(request.getParameter("type").equals("p")){
			user_story = ((LinkedList<UserStory>)session.getAttribute("pending")).get(Integer.parseInt(request.getParameter("index")));
		}
		else{
			user_story = ((LinkedList<UserStory>)session.getAttribute("estimated")).get(Integer.parseInt(request.getParameter("index")));
		}
	}catch(Exception e){
		user_story = (UserStory)session.getAttribute("UserStory");
	}
	if (user_story == null)
	{
		response.sendRedirect("MyUserStories.jsp");
	}
%>
	<head>
	<script type="text/javascript">
		function show_confirm() {
		var r=confirm("Do you want to remove this User Story?");
		return r;
		}
	</script>
	<link rel="stylesheet" type="text/css" href="styles.css" title="Style 1" />
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>
			User Story: <%= user_story.getTitle() %>
		</title>
	</head>
	<body>
		<h1>User Story: <%= user_story.getTitle() %></h1>
		<a href="/SignOut" class="Signout">SignOut</a>
		<br/>
		<hr />
    		<p><b>Description:</b></p>
    	<p class="Tab"><%= user_story.getDescription() %></p>
    <% 
    if(!user_story.getTestNotes().equals(null)  && !user_story.getTestNotes().equals("")){
    %>
        <p><b>
        	Test Notes:
        </b></p>
        <p class="Tab">
        	<%= user_story.getTestNotes() %>
        </p>
    <%
    }
    session.setAttribute("UserStory", user_story);
    %>
     <% 
    	User currentUser = (User)session.getAttribute("User");
   	 if(user_story.getCreator().equals(currentUser) && !request.getParameter("type").equals("e")){
   		 %>
   		 </br>
   		 <table align="left"  border="0" cellspacing="0" cellpadding="5">
    	<tr>
    <td><input type="button" value="Edit" onclick="location.href='EditUserStory.jsp'"></td>
    <td><input type="button" value="Select Estimators" onclick="location.href='EditEstimators.jsp'"></td>
    <form action="/RemoveUserStory" method="post">
    	<td><input type="submit" value="Remove" onclick="return show_confirm()"></td>
    </form>
    </tr>
    </table>
    <% }
   	 %>
   	 </br> </br>
    <hr/>
    
    <a href="MyUserStories.jsp">Back!</a>
</body>
</html>